<?php
  /**
   * @author 2mdc.com
   * @version 
   */

  include_once dirname(__FILE__) . '/cCreateElement.inc';

  class cCreateFooter extends cCreateElement {
    static private $rscInstance = NULL;

    private function __construct() {
    }

    public function __destruct() {
    }

    public function __toString() {
      return $this->xml;
    }

    static public function getInstance() {
       if(self::$rscInstance == NULL) {
          self::$rscInstance = new cCreateFooter();
       }
       return self::$rscInstance;
    }

    protected function fGenerateFTR() {
      $this->xml = '__GENERATEFTR__';
    }

    protected function fGenerateP() {
      $this->xml = str_replace('__GENERATEFTR__', '<'.cCreateElement::NAMESPACE.':p>__GENERATEP__</'.cCreateElement::NAMESPACE.':p>', $this->xml);
    }

    protected function fGenerateR() {
      if(!empty($this->xml)) {
        if(preg_match("/__GENERATEP__/", $this->xml)) {
          $this->xml = str_replace('__GENERATEP__', '<'.cCreateElement::NAMESPACE.':r>__GENERATER__</'.cCreateElement::NAMESPACE.':r>__GENERATERSUB__', $this->xml);
        }
        elseif(preg_match("/__GENERATER__/", $this->xml)) {
          $this->xml = str_replace('__GENERATER__', '<'.cCreateElement::NAMESPACE.':r>__GENERATER__</'.cCreateElement::NAMESPACE.':r>__GENERATERSUB__', $this->xml);
        }
        elseif(preg_match("/__GENERATERSUB__/", $this->xml)) {
          $this->xml = str_replace('__GENERATERSUB__', '<'.cCreateElement::NAMESPACE.':r>__GENERATER__</'.cCreateElement::NAMESPACE.':r>__GENERATERSUB__', $this->xml);
        }
      }
      else {
        $this->xml = '<'.cCreateElement::NAMESPACE.':r>__GENERATER__</'.cCreateElement::NAMESPACE.':r>__GENERATERSUB__';
      }
    }

    protected function fGeneratePTAB($strRelativeTo = 'margin', $strAlignment = 'right', $strLeader = 'none') {
      $this->xml = str_replace('__GENERATER__', '<'.cCreateElement::NAMESPACE.':ptab '.cCreateElement::NAMESPACE.':relativeTo="'.$strRelativeTo.'" '.cCreateElement::NAMESPACE.':alignment="'.$strAlignment.'" '.cCreateElement::NAMESPACE.':leader="'.$strLeader.'"></'.cCreateElement::NAMESPACE.':ptab>', $this->xml);
    }

    protected function fGenerateFLDSIMPLE() {
      $this->xml = str_replace('__GENERATERSUB__', '<'.cCreateElement::NAMESPACE.':fldSimple '.cCreateElement::NAMESPACE.':instr=" PAGE   \* MERGEFORMAT "></'.cCreateElement::NAMESPACE.':fldSimple>', $this->xml);
    }

    public function fCreateFooter() {
      $this->xml = '';
      $arrArgs = func_get_args();

      $this->fGenerateFTR();
      $this->fGenerateP();
      $this->fGenerateR();
      $this->fGenerateT($arrArgs[0]);
      if($arrArgs[1]['pager'] == 'true') {
        $this->fGenerateR();
        $this->fGeneratePTAB('margin', $arrArgs[1]['pagerAlignment']);
        $this->fGenerateFLDSIMPLE();
      }
    }
  }
?>